<% truncate_length_for_boxes = 22 -%>
<%= javascript_include_tag 'toggler.js' %>
<%= javascript_include_tag "variable_table_check.js" -%>
<%= stylesheet_link_tag 'survey_ul'%>
<%= stylesheet_link_tag 'faux_table'%>
<ul class="buttons">
  <%= hidden_field_tag "format_type", "csv" -%>
	<% if current_user && current_user.id != @archive.contributor_id %>
	<div id="recommended" style="display: inline;">
		<% if @recommended == true %>
			<%= render :partial => "recommendations/thumbs_down", :locals => {:item => @archive} -%>
	<% else %>
		<%= render :partial => "recommendations/thumbs_up", :locals => {:item => @archive} -%>
	<% end %>
	</div>
	<% end %>
	    <li><%= icon('download', download_stats_script_csvarchive_url + "?type=spss", nil, {:title => "Download all the scripts to load the data into your stats package.  You will need to supply the data yourself."}, "Download spss files") -%></li>
	    <li><%= icon('download', download_stats_script_csvarchive_url + "?type=stata", nil, {:title => "Download all the scripts to load the data into your stats package.  You will need to supply the data yourself."}, "Download stata files") -%></li>
  <% if Authorization.is_authorized?("download", nil, @archive, current_user) -%>
    <li><%= icon('download', download_csvarchive_url + "?type=CSV", "Download file", {:id=>"download_button", :title => "Download the data, metadata and any stats package scripts."}, "Download extract as:") -%></li>
  <%= select_tag :download_type, options_for_select(download_type_options,"CSV"), {:onchange=>"changeURL(this.value)"} -%>
  <% end -%>
  <% if Authorization.is_authorized?("edit", nil, @archive, current_user) -%>
    <li><%= icon "edit", edit_csvarchive_path(@archive), nil, nil, "Edit" -%></li>
  <% end %>
  <% if Authorization.is_authorized?("destroy", nil, @archive, current_user) -%>
    <li><%= icon('destroy', csvarchive_path(@archive), nil, { :confirm => 'This deletes the Data Extract and links to any methods/scripts and surveys. Are you sure?', :method => :delete }, 'Delete Data Extract') -%></li>
  <% end -%>
</ul>

<h1 class="contribution_title">Data Extract: <%= link_to(h(@archive.title), csvarchive_path(@archive)) -%><div class="inline" id="award"><%= render :partial => "recommendations/awards", :locals => { :count => @archive.recommendations.size } %></div></h1>

<div class="show_basic">
  <div class="box_about_actor">
    <p>
      <b>Title:</b>
      <% unless @archive.title.blank? -%>
        <span class="title"><%=h @archive.title -%></span>
      <% else -%>
      <p class="none_text">
        No title
      </p>
    <% end -%>
    </p>
    <p>
      <b>Description</b>
      <% unless @archive.description.blank? -%>
      <div class="box_standout" style="background-color:#FFFFFF;">
        <%= simple_format(white_list(@archive.description)) -%>
      </div>
    <% else -%>
      <p class="none_text">
        No description
      </p>
    <% end -%>
	<div>
		<%= render :partial => "total_vars" %>
	</div>
	<br/>
	<% if current_user %>
	<div class="link_box">
	Show: 
	<%= link_to_remote "Only my links", :url=> show_links_csvarchives_path, :with=> "'link_state=mine&extract_id=#{@archive.id}'" %>, 
	<%= link_to_remote "All links", :url=> show_links_csvarchives_path, :with=> "'link_state=all&extract_id=#{@archive.id}'" %>
	</div>
	<% end %>
	<div class="actual_link_box">

<div id="links">
		<%= render :partial => "links" %>
</div>
</div>
<br/>
<br/>
	<%= render :partial => "complete" %>
    <%= render :partial => "datetime_info", :locals => { :resource => @archive } -%>
  </div>
  <% form_remote_tag :url => { :action => "add_to_cart"} do -%>
	<%= hidden_field_tag 'extract_id', @archive.id %>
    <%= hidden_field_tag 'submit', 'add' %>
    <br/>
<%= render :partial => "extract_bar" -%>
    <br/>
    <div id="table_header" class="faux_table_header_container">
      <%= render :partial => "surveys/table_header",:locals=>{:sorted_variables => @sorted_variables} -%>
    </div>
    <div id="table_container" class="faux_table_container">
      <%= render :partial => "surveys/table",:locals=>{:lineage => true, :extract_lineage => true, :extract_id => @archive.id, :sorted_variables => @sorted_variables} -%>
    </div>
    <br/>
  <% end %>
</div>
<div style="clear: both;"></div>
<% if current_user %>
<div class="left" id="extract-note-box">
	<% if current_user %>
	<h3>Notes</h3>
	  <%= render :partial => "notes/add_note", :locals=>{:resource_id => @archive.id} -%>
			<% @notes.each do |note| %>
			<%= render :partial => "notes/note", :locals=>{:note=>note} %>
			<% end %>
			<div id="new_note">
				</div>
				<% end %>
</div>
<div class="resource-comments right" id="extract-comment-box">
<h3>Comments</h3>
  <%= render :partial => "comments/add_comment", :locals=>{:resource_id => @archive.id} -%>
		<% @comments.each do |comment| %>
		<%= render :partial => "comments/comment", :locals=>{:comment=>comment} %>
		<% end %>
		<div id="new_comment">
		</div>
</div>
<% end %>
<script type="text/javascript">
  function changeURL(value) {
    URL = document.getElementById("download_button").href;
    URL = "<%= download_csvarchive_url -%>" + "?type=" + value;
    document.getElementById("download_button").href = URL;
  }
</script>
